<?php

class Mail{
	private $sender;
	private $reciever;
	private $msg;
	private $notSend;
	
	public function __construct($sender, $reciever, $msg, $notSend) {
		$this->setSender($sender);
		$this->setReciever($reciever);
		var_dump($reciever);
		$this->setMsg($msg);
		$this->setNotSend($notSend);
	}
	
	public function setSender($sender){
		if (get_class($sender) != 'Profile'){
			throw new Exception("The sender is not an object of Profile !");
		}
		$this->sender = $sender;
		$this->updateMailData();
	}
	
	public function getSender(){
		return $this->sender;
		
	}
	
	public function setReciever($reciever){
		if (get_class($reciever) != 'Profile'){
			throw new Exception("The reciever is not an object of Profile !");
		}
		$this->reciever = $reciever;
		$this->updateMailData();
	}
	
	public function getReciever(){
		return $this->reciever;
	}
	
	public function setMsg($msg){
		$this->msg = strip_tags($msg);
		$this->updateMailData();
	}
	
	public function getMsg(){
		return $this->msg;
	}
	
	public function setNotSend(DateTime $notSend){
		$today = new DateTime();
		
		if(get_class($date) != "DateTime") {
			throw new  Exception("Input for send time should be a DateTime object!");
		}
		
		if($date<$today) {
			throw new  Exception("Send time can`t be date in the past.");
		}
		
		$this->lockedTime = $date->format('Y-m-d H:i:s');
		$this->updateMailData();
		
	}
	
	public function getNotSend(){
		return $this->notSend;
	}
	
	public function updateMailData(){
		$mailData = array();
		$mailData['sender'] = $this->sender->getProfileID();
		$mailData['reciever'] = $this->reciever->getProfileID();
		$mailData['msg'] = $this->msg;
		$mailData['not_send'] = $this->notSend;
		DBUtils::insertMailData($mailData);
	}
}
?>
